package com.yhb.demo.handlers;

import com.yhb.demo.beans.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class ThymeleafController {
    @RequestMapping("/test/myindex")
    public String indexHandle(Model model){
        model.addAttribute("welcome","hello Thymeleaf world");

        Student student =new Student("张三",23);
        model.addAttribute("student", student);

        model.addAttribute("gender", "male");

        model.addAttribute("age", 35);

        Student student1=new Student("张三",23);
        Student student2=new Student("李四",21);
        Student student3=new Student("王五",25);
        //创建List集合
        List<Student> students=new ArrayList<>();
        students.add(student1);
        students.add(student2);
        students.add(student3);
        model.addAttribute("students", students);

        //创建map
        Map<String,Student> stuMap= new HashMap<>();
        stuMap.put("stu1", student1);
        stuMap.put("stu2", student2);
        stuMap.put("stu3", student3);
        model.addAttribute("stuMap", stuMap);

        model.addAttribute("welcome", "<h2>Thymeleaf,<br/> I'm learning.</h2>");
        model.addAttribute("photo", "test.jpg");

        model.addAttribute("elementId", "reddiv");
        model.addAttribute("bgColor", "red");

        return "index";
    }
}
